const propertyMaps = new Map()
    .set('newsletters_isp_SyncUrl', InputProperty.generate('管局侧报备地址'))
    // .set('newsletters_WebserviceUrl', InputProperty.generate('企业侧接口地址'))
    //.set('newsletters_ispId', InputProperty.generate('报备单位标识'))
    .set('newsletters_userName', InputProperty.generate('经营许可证号'))
    .set('newsletters_passwd', InputProperty.generate('用户身份认证口令'))
    .set('newsletters_authenticationkey', InputProperty.generate('消息认证密钥'))
    .set('newsletters_encryptAlgorithm', InputProperty.generate('加密算法'))
    .set('newsletters_AESKey', InputProperty.generate('数据加密密钥'))
    .set('newsletters_AESOffset', InputProperty.generate('加密密钥偏移量'))
    .set('newsletters_hashAlgorithm', InputProperty.generate('哈希算法'))
    .set('newsletters_compressionFormat', InputProperty.generate('压缩格式'))
    // .set('newsletters_isp_sync_mode', InputProperty.generate('数据同步模式'))
    // .set('newsletters_report_limit', InputProperty.generate('上报日志条数限制'))
    // .set('newsletters_report_rate', InputProperty.generate('自动上报频率限制'))
    // .set('newsletters_eutask_limit', InputProperty.generate('下发EU条数限制'))
    // .set('newsletters_com_version', InputProperty.generate('系统接口版本'))
    // .set('newsletters_ftp_host', InputProperty.generate('FTP主机名'))
    // .set('newsletters_ftp_user', InputProperty.generate('FTP用户名称'))
    // .set('newsletters_ftp_mode', InputProperty.generate('连接模式'))
    // .set('newsletters_ftp_path', InputProperty.generate('FTP主目录'))
    // .set('newsletters_ftp_pwd', InputProperty.generate('FTP密码'))
    // .set('newsletters_ftp_port', InputProperty.generate('FTP端口'))

    .set('sysSettings_login_mail_verify', InputProperty.generate('登录邮件验证'))
    .set('sysSettings_login_remote', InputProperty.generate('异地登录开关'))
    .set('sysSettings_system_warn', InputProperty.generate('应用系统预警值'))
    .set('sysSettings_HouseMonitor', InputProperty.generate('机房异常监测'))
    .set('sysSettings_retain_icp_day', InputProperty.generate('活跃资源设置'))
    .set('sysSettings_retain_illegal_day', InputProperty.generate('非法信息设置'))
    .set('sysSettings_retain_monitor_log_day', InputProperty.generate('监测日志设置'))
    .set('sysSettings_retain_filter_log_day', InputProperty.generate('过滤日志设置'))
    .set('sysSettings_retain_visitlog_day', InputProperty.generate('访问日志设置'))
    .set('sysSettings_retain_netvirus_day', InputProperty.generate('网络威胁设置'))
    .set('sysSettings_retain_ispfile_day', InputProperty.generate('通讯文件设置'))
    .set('sysSettings_psession_timeout', InputProperty.generate('记住我是谁'))
    .set('sysSettings_loginsession_timeout', InputProperty.generate('登录会话'))
    .set('sysSettings_ntp_state', InputProperty.generate('启动NTP服务'))
    .set('sysSettings_ntp_domain', InputProperty.generate('NTP同步服务器'))
    .set('sysSettings_snmp_state', InputProperty.generate('SNMP服务状态'))
    .set('sysSettings_snmp_key', InputProperty.generate('CommunityString'))
    .set('sysSettings_snmp_location', InputProperty.generate('Location'))
    .set('sysSettings_snmp_contact', InputProperty.generate('SystemContactEmailAddress'))

    .set('alarmSetting_mail_host', InputProperty.generate('邮件服务器'))
    .set('alarmSetting_mail_ssl', InputProperty.generate('加密连接(SSL)'))
    .set('alarmSetting_mail_port', InputProperty.generate('SMTP端口'))
    .set('alarmSetting_mail_user', InputProperty.generate('邮箱账号'))
    .set('alarmSetting_mail_pass', InputProperty.generate('邮箱密码'))
    .set('alarmSetting_mail_charset', InputProperty.generate('邮件编码'))
    .set('alarmSetting_mail_cus', InputProperty.generate('客户报警邮箱'))
    .set('alarmSetting_mail_test_address', InputProperty.generate('测试邮件地址'))

    .set('sysLog_log_level', InputProperty.generate('系统日志级别'))
    .set('sysLog_max_logfile_size', InputProperty.generate('日志大小'))
    .set('sysLog_backup_logfile', InputProperty.generate('备份日志'))

    .set('filingSettings_icp_api_url', InputProperty.generate('备案API地址'))
    .set('filingSettings_icp_query_type', InputProperty.generate('API类型'))
    .set('filingSettings_icp_api_user', InputProperty.generate('API用户'))
    .set('filingSettings_icp_api_pwd', InputProperty.generate('API密码'))
    .set('filingSettings_ipInvalid', InputProperty.generate('接口类型说明'))
    .set('filingSettings_domainInvalid', InputProperty.generate('备案查询模式'))
    .set('filingSettings_icp_query_mode', InputProperty.generate('IP网站备案检查'))
    .set('filingSettings_check_icp_day', InputProperty.generate('域名解析IP检查'))

    .set('shieldSettings_autoHandleillegalWeb', InputProperty.generate('违规网站处置'))
    .set('shieldSettings_autoHandleNoIcp', InputProperty.generate('未备案网站处置'))
    .set('shieldSettings_alarmHandleKeyword', InputProperty.generate('非法信息处置'))
    .set('shieldSettings_autoHandleKeyword', InputProperty.generate('非法信息处置'))
    .set('shieldSettings_alarmHandleMedia', InputProperty.generate('非法多媒体处置'))
    .set('shieldSettings_autoHandleMedia', InputProperty.generate('非法多媒体处置'))
    .set('shieldSettings_bizUrl', InputProperty.generate('业务系统验证网址'))

    .set('DUSettings_DuUrl', InputProperty.generate('访问日志查询接口地'))
    .set('DUSettings_du_passwd', InputProperty.generate('身份认证密码'))
    .set('DUSettings_du_encryptAlgorithm', InputProperty.generate('加密算法'))
    .set('DUSettings_du_AESKey', InputProperty.generate('数据加密密钥'))
    .set('DUSettings_du_AESOffset', InputProperty.generate('加密密钥偏移量'))
    .set('DUSettings_du_hashAlgorithm', InputProperty.generate('哈希算法'))
    .set('DUSettings_du_compressionFormat', InputProperty.generate('压缩格式'))
    .set('DUSettings_duftp_host', InputProperty.generate('主机名'))
    .set('DUSettings_duftp_port', InputProperty.generate('端口'))
    .set('DUSettings_duftp_user', InputProperty.generate('用户名'))
    .set('DUSettings_duftp_pwd', InputProperty.generate('密码'))
    .set('DUSettings_duftp_path', InputProperty.generate('访问日志传输配置'))

    .set('MUSettings_DuMediaUrl', InputProperty.generate('非法多媒体查询接口地址'))
    .set('MUSettings_mu_passwd', InputProperty.generate('身份认证密码'))
    .set('MUSettings_mu_encryptAlgorithm', InputProperty.generate('加密算法'))
    .set('MUSettings_mu_AESKey', InputProperty.generate('数据加密密钥'))
    .set('MUSettings_mu_AESOffset', InputProperty.generate('加密密钥偏移量'))
    .set('MUSettings_mu_hashAlgorithm', InputProperty.generate('哈希算法'))
    .set('MUSettings_mu_compressionFormat', InputProperty.generate('压缩格式'))
    .set('MUSettings_muftp_host', InputProperty.generate('主机名'))
    .set('MUSettings_muftp_port', InputProperty.generate('端口'))
    .set('MUSettings_muftp_user', InputProperty.generate('用户名'))
    .set('MUSettings_muftp_pwd', InputProperty.generate('密码'))
    .set('MUSettings_muftp_path', InputProperty.generate('访问日志传输配置'))


new Vue({
    el: '#app',
    data: function () {
        return {
            activeName: "first",
            newsletters: {
                newsletters_isp_SyncUrl: '',
                // newsletters_WebserviceUrl: '',
                // newsletters_ispId: '',
                newsletters_userName: '',
                newsletters_passwd: '',
                newsletters_authenticationkey: '',
                newsletters_encryptAlgorithm: '',
                newsletters_AESKey: '',
                newsletters_AESOffset: '',
                newsletters_hashAlgorithm: '',
                newsletters_compressionFormat: '',
                // newsletters_isp_sync_mode: '',
                // newsletters_report_limit: '',
                // newsletters_report_rate: '',
                // newsletters_eutask_limit: '',
                // newsletters_com_version: '',
                // newsletters_ftp_host: '',
                // newsletters_ftp_user: '',
                // newsletters_ftp_mode: '',
                // newsletters_ftp_path: '',
                // newsletters_ftp_pwd: '',
                // newsletters_ftp_port: '',
            },
            sysSettings: {
                sysSettings_login_mail_verify: 0,
                sysSettings_login_remote: '',
                sysSettings_system_warn: '',
                sysSettings_HouseMonitor: 1,
                sysSettings_retain_icp_day: '',
                sysSettings_retain_illegal_day: '',
                sysSettings_retain_monitor_log_day: '',
                sysSettings_retain_filter_log_day: '',
                sysSettings_retain_visitlog_day: '',
                sysSettings_retain_netvirus_day: '',
                sysSettings_retain_ispfile_day: '',
                sysSettings_psession_timeout: '',
                sysSettings_loginsession_timeout: '',
                sysSettings_ntp_state: false,
                sysSettings_ntp_domain: '',
                sysSettings_snmp_state: '',
                sysSettings_snmp_key: '',
                sysSettings_snmp_location: '',
                sysSettings_snmp_contact: '',
                sysSettings_retain_monitor_log_day: '',
                sysSettings_retain_filter_log_day: ''
            },
            alarmSetting: {
                alarmSetting_mail_host: '',
                alarmSetting_mail_ssl: 0,
                alarmSetting_mail_port: '',
                alarmSetting_mail_user: '',
                alarmSetting_mail_pass: '',
                alarmSetting_mail_charset: "UTF8",
                alarmSetting_mail_cus: '',
                alarmSetting_mail_test_address: '',
            },
            sysLog: {
                sysLog_log_level: '',
                sysLog_max_logfile_size: '',
                sysLog_backup_logfile: false,
            },
            filingSettings: {
                filingSettings_icp_api_url: '',
                filingSettings_icp_query_type: 0,
                filingSettings_icp_api_user: '',
                filingSettings_icp_api_pwd: '',
                filingSettings_ipInvalid: 0,
                filingSettings_domainInvalid: 0,
                filingSettings_icp_query_mode: 0,
                filingSettings_check_icp_day: '',
            },
            shieldSettings: {
                shieldSettings_autoHandleillegalWeb: 0,
                shieldSettings_autoHandleNoIcp: 0,
                shieldSettings_alarmHandleKeyword: '',
                shieldSettings_autoHandleKeyword: 0,
                shieldSettings_alarmHandleMedia: '',
                shieldSettings_autoHandleMedia: 0,
                shieldSettings_bizUrl: '',
            },
            DUSettings: {
                DUSettings_DuUrl: '',
                DUSettings_du_passwd: '',
                DUSettings_du_encryptAlgorithm: 1,
                DUSettings_du_AESKey: '',
                DUSettings_du_AESOffset: '',
                DUSettings_du_hashAlgorithm: 1,
                DUSettings_du_compressionFormat: 1,
                DUSettings_duftp_host: '',
                DUSettings_duftp_port: '',
                DUSettings_duftp_user: '',
                DUSettings_duftp_pwd: '',
                DUSettings_duftp_path: '',
            },
            MUSettings: {
                MUSettings_DuMediaUrl: '',
                MUSettings_mu_passwd: '',
                MUSettings_mu_encryptAlgorithm: '',
                MUSettings_mu_AESKey: '',
                MUSettings_mu_AESOffset: '',
                MUSettings_mu_hashAlgorithm: '',
                MUSettings_mu_compressionFormat: '',
                MUSettings_muftp_host: '',
                MUSettings_muftp_port: '',
                MUSettings_muftp_user: '',
                MUSettings_muftp_pwd: '',
                MUSettings_muftp_path: '',
            },
            propertyMaps: propertyMaps,
            dataCopy: {
                newsletters: {},
                sysSettings: {},
                alarmSetting: {},
                sysLog: {},
                filingSettings: {},
                shieldSettings: {},
                DUSettings: {},
                MUSettings: {},
            },
            currentTime: rx.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
        }
    },
    methods: {
        async syncNTP() {
            if (!this.sysSettings.sysSettings_ntp_state) {
                await rxPrompt.msg('请勾选启动NTP服务器选项')
                return;
            }

            //同步
            const property = this.propertyMaps.get('sysSettings_ntp_domain')
            const data = SystemConfig.generate('sysSettings_ntp_domain', this.sysSettings.sysSettings_ntp_domain, property['title'], 1, '1', property['id'])
            const res = await sysConfigurationApi.syncNTP(data);
            if (res.code === 200) {
                await rxPrompt.msg('同步成功')
            } else {
                await rxPrompt.msg(`同步失败,${res.msg}`)
            }
        },
        async sendTestEmail() {
            const res = await this.$validator.validateAll('alarmSetting_mail_test_address')
            if (!res) {
                return;
            }
            const testRes = await sysConfigurationApi.testEmail(this.alarmSetting.alarmSetting_mail_test_address);
            if (testRes.code === 200 && testRes.data === true) {
                await rxPrompt.msg('测试成功')
            } else {
                await rxPrompt.msg('测试失败')
            }
        },
        async initFormData(property) {
            const res = (await sysConfigurationApi.listPrefix({'prefix': property})).data;
            await this.echo({'data': res, 'property': property});
        },
        async formSub(obj) {
            const data = Object.keys(obj).map((val, index, arr) => {
                return SystemConfig.generate(val, obj[val], this.propertyMaps.get(val)['title'], 1, '1', this.propertyMaps.get(val)['id'])
            })
            //提交
            this.$validator.validateAll(obj).then(async (result) => {
                if (result) {
                    //  提交数据
                    const res = await sysConfigurationApi.addOrUpdateBatch(data);
                    if (res.code === 200) {
                        await rxPrompt.msg('修改成功')
                        //location.href = '/';
                    } else {
                        await rxPrompt.msg('修改失败')
                    }
                } else {
                    rxPrompt.dangerMsg("输入存在错误！");
                }
            });
        },
        formRest(property) {
            this[property] = _.cloneDeep(this.dataCopy[property]);
        },
        async echo(param) {
            const newData = {};
            (async () => {
                const str = JSON.stringify(newData)
                await rx.wait(() => str !== JSON.stringify(newData))

                this[param['property']] = newData;
                this.dataCopy[param['property']] = _.cloneDeep(newData);
            })()
            param['data'].forEach((val, index, arr) => {
                newData[val.configKey] = val['configValue'];
                this.propertyMaps.get(val.configKey)['id'] = val['id'];
            })
        },
    },
    mounted: async function () {
        await this.initFormData('newsletters');
        await this.initFormData('sysSettings');
        await this.initFormData('alarmSetting');
        await this.initFormData('sysLog');
        await this.initFormData('filingSettings');
        await this.initFormData('shieldSettings');
        // await this.initFormData('DUSettings');
        // await this.initFormData('MUSettings');
        var _this = this;
        this.timer = setInterval(function () {
            _this.currentTime = rx.dateFormat(new Date(), 'yyyy-MM-dd hh:mm:ss')
        }, 1000);

    },
    beforeDestroy() {
        if (this.timer) {
            clearInterval(this.timer);//在vue实例销毁钱，清除我们的定时器
        }
    }
})